package com.echo.auth.business.controller;

import com.echo.model.resq.response.result.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.oauth2.provider.AuthorizationRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.security.Principal;
import java.util.Map;

/**
 * @version: V1.0
 * @author: chentailai
 * @className: AuthController
 * @packageName: com.echo.auth.business.controller
 * @description: 认证控制器
 * @data: 2020/3/27 11:58
 **/
@Slf4j
@Controller
public class OAuthController {

    public static final String LOGIN_HTML = "/login/login";

    public static final String GANT_HTML = "/login/grant";

    @GetMapping("/user")
    public Principal user(Principal user) {
        return user;
    }

    @RequestMapping("/hello")
    @ResponseBody
    public String hello(String hello) {
        log.info("you say:" + hello);
        return hello;
    }

    @RequestMapping("/oauth/login")
    public String loginPage(Model model) {
        model.addAttribute("loginProcessUrl", "/echo-auth-server/oauth/authorize");
        log.info("进入登录界面");
        return LOGIN_HTML;
    }

//    @RequestMapping("/oauth/confirm_access")
//    public ModelAndView getAccessConfirmation(Map<String, Object> model, HttpServletRequest request) throws Exception {
//        AuthorizationRequest authorizationRequest = (AuthorizationRequest) model.get("authorizationRequest");
//        ModelAndView view = new ModelAndView();
//        view.addObject("clientId", authorizationRequest.getClientId());
//        view.setViewName(GANT_HTML);
//        return view;
//    }

}
